package yun2.ch2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class KuoHaoPiPei {

	public static void main(String[] args) throws IOException {
		BufferedReader br =  new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		int ret = minAddToMakeValid(s);//"())"   String,charAt(i)
		System.out.println(ret);
	}
	
	public static int minAddToMakeValid(String s) {
		Stack<Character> st = new Stack<>();
		char ch;
		for(int i=0;i<s.length();i++) {
			ch = s.charAt(i);
			if(ch == '(') {
				st.push(ch);
			}else {// )
				if(!st.isEmpty() && st.peek()=='(') {
					st.pop();
				}else {
					st.push(ch);
				}
			}
		}
		return st.size();
	}


}
